﻿using UnityEngine;
using System.Text;


public class ChatUIComponent : MonoBehaviour
{
	public UITextList textList;
	public bool fillWithDummyData = false;
	
	UIInput mInput;

	/// <summary>
	/// Add some dummy text to the text list.
	/// </summary>


	void Start ()
	{
		mInput = GetComponent<UIInput>();
		mInput.label.maxLineCount = 1;
		
		if (fillWithDummyData && textList != null)
		{
			textList.Add( "[FF0000]Wellcome to World of SA. and thank you for play it. enjoy self." );
//			for (int i = 0; i < 30; ++i)
//			{
//				textList.Add(((i % 2 == 0) ? "[FFFFFF]" : "[AAAAAA]") +
//				             "This is an example paragraph for the text list, testing line " + i + "[-]");
//			}
		}
	}


	public void addChat( string name , string chat )
	{
		string str = @"[FFFF00]" + @name + @"：" + @chat;

		textList.Add( str );
	}

	
	/// <summary>
	/// Submit notification is sent by UIInput when 'enter' is pressed or iOS/Android keyboard finalizes input.
	/// </summary>
	
	public void OnSubmit ()
	{
		if ( textList != null )
		{
			// It's a good idea to strip out all symbols as we don't want user input to alter colors, add new lines, etc
			string text = NGUIText.StripSymbols( mInput.value );
			
			if ( !string.IsNullOrEmpty( text ) )
			{
				//textList.Add( text );
				mInput.value = "";
				mInput.isSelected = false;

				ChatNetHandler.instance.sendChatMsg( text );
			}
		}
	}
}
